package logic

import (
	"context"
	"course_srv/models/mysql"
	"errors"

	"course_srv/course"
	"course_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCourseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseShowLogic {
	return &CourseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CourseShowLogic) CourseShow(in *course.CourseShowRequest) (*course.CourseShowResponse, error) {
	var c mysql.Course
	err := c.CourseShow(int(in.Id))
	if err != nil {
		return nil, errors.New("课程详情展示失败")
	}
	if c.ID == 0 {
		return nil, errors.New("课程详情展示失败")
	}

	return &course.CourseShowResponse{Id: int32(c.ID), Name: c.Name, Teacher: c.Teacher, Intro: c.Intro, Price: float32(c.Price), Cover: c.Cover, Video: c.Video}, nil
}
